package titan.utils;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

import titan.messages.Messages;

/**
 * Class StatusBar.
 * Allows the exhibition of a text to indicate a function status
 */
public class StatusBar {
	private Text bar;
	private Shell shell;

	/**
	 * Creates a status bar
	 * @param display - the parent shell
	 */
	public StatusBar(Shell display) {
		// create window
		shell = new Shell(display, SWT.APPLICATION_MODAL| SWT.DIALOG_TRIM);
		// get parent window size
		Rectangle r = display.getBounds();
		// set window size
		shell.setBounds(r.x+(r.height/2)-150, r.y+(r.width/2)-10, 300, 20);
		// create composite
		Composite comp = new Composite(shell, SWT.NONE);
		// create a not editable Text field with 300x20 size
		bar = new Text(comp, SWT.NONE);
		bar.setText(Messages.Connecting);
		bar.setEditable(false);
		bar.setSize(300, 20);
		//set window layout to row layout
		shell.setLayout(new RowLayout());
	}

	/**
	 * Open status bar
	 */
	public void open() {
		shell.pack();
		shell.open();
	}

	/**
	 * Set status bar text
	 * @param text - the text to be set
	 */
	public void setText(String text){
		bar.setText(text);
		shell.update();
	}

	/**
	 * Close status bar
	 */
	public void close(){
		shell.close();
	}
}